<template>
	<view class="feed_back clearfix">
		<!-- 信息留言 -->
		<view class="textarea_area">
			<textarea class="textarea" v-model="content" placeholder="您的只言片语，我们聆听" name="" id="" cols="30" rows="10"></textarea>
			<view class="updata_img">
				<image :src="feedImg" v-show="feedImg" mode="" @click="lookdataImg"></image>
				<image src="../../static/image/add_img@2x.png" v-show="!feedImg" @click="successImage"></image>
			</view>
		</view>
		<!-- 反馈类型 -->
		<view class="back_type">
			<view class="back_type_top">
				<text>选择反馈类型</text>
			</view>
			<view class="back_type_con">
				<view v-for="(item,index) in backTypes" :key="item.id" @click="typeBack(item)">
					<image :src="currentImg == item.id? '../../static/image/rb_s@2x.png' : '../../static/image/rb_n@2x.png'" mode=""></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<!-- 大图预览 -->
		<view class="dataImg" v-show="dataImg" @click="lookdataImg">
			<image :src="feedImg" mode=""></image>
		</view>
		<!-- 提交按钮 -->
		<view class="submit" @click="postfeedback">提交</view>
	</view>
</template>

<script>
	import { pathToBase64, base64ToPath } from '../../components/gsq-image-tools/image-tools/index.js'
	import {
		throtTling
	} from '../../utils/throttling.js'
	export default {
		data() {
			return {
				feedImg: '',
				category: 'image',
				currentImg: '1',
				// 反馈类型id
				typeId: '1',
				// 反馈内容
				content: '',
				// 图片地址
				file: '',
				// 是否显示大图模式
				dataImg: false,
				backTypes: []
			};
		},
		mounted() {
			this.feedBackType()
		},
		methods: {
			successImage(e) {
				let that = this
				uni.chooseImage({
					current: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: (res) => {
						pathToBase64(res.tempFilePaths[0]).then(res => {
							that.$http({
								url: '/wxapi/UploadImageApi/UploadImage',
								method: 'POST',
								data: {
									file: res
								}
							}).then(res => {
								if (res.code == 200) {
									that.feedImg = res.data
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						})
						
					}
				})
			},
			
			typeBack(item) {
				this.currentImg = item.id
			},
			// 提交
			postfeedback: throtTling(function() {
				let data = {
					content: this.content,
					image: this.feedImg,
					type: this.typeId
				}
				this.$http({
					url: '/wxapi/FeedbackApi/postfeedback',
					method: 'POST',
					data: { ...data
					}
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/userInfo/userInfo'
							})
						}, 1000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},1000),
			// 查看反馈类型列表
			feedBackType() {
				this.$http({
					url: '/wxapi/FeedbackApi/FeedBackType',
					method: 'POST'
				}).then(res => {
					if (res.code == 200) {
						this.backTypes = res.data
						this.currentImg = res.data[0].id
					}
				})
			},
			// 查看大图
			lookdataImg() {
				this.dataImg = !this.dataImg
			}
		}
	}
</script>

<style lang="less">
	.feed_back {
		height: 100%;
		background-color: #f3f5f8;

		.textarea_area {
			position: relative;
			margin: 10rpx;
			padding: 20rpx 40rpx;
			height: 330rpx;
			background-color: #fff;

			.extarea {
				width: 100%;
				height: 200rpx;
			}

			.updata_img {
				display: flex;
				position: absolute;
				bottom: 20rpx;
				// width: 130rpx;
				height: 130rpx;

				image {
					width: 130rpx;
					height: 100%;
				}
			}
		}

		.back_type {
			color: #333;
			font-size: 30rpx;
			background-color: #fff;

			.back_type_top {
				padding: 0 40rpx;
				height: 100rpx;
				line-height: 100rpx;
				border-bottom: 5rpx solid #CBCBCB;
			}

			.back_type_con {
				display: flex;
				justify-content: space-around;
				padding: 0 40rpx;
				height: 100rpx;
				line-height: 100rpx;

				view {
					flex: 1;
					text-align: center;

					image {
						margin-right: 20rpx;
						width: 36rpx;
						height: 36rpx;
					}
				}
			}
		}

		.submit {
			margin: 0 30rpx;
			margin-top: 240rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			color: #fff;
			font-size: 40rpx;
			border-radius: 45rpx;
			background-color: #09A9F9;
		}
	}

	.dataImg {
		position: fixed;
		top: 50%;
		right: 50%;
		transform: translate(50%, -50%);
		width: 90%;
		height: 60%;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
